<?php

if (!defined('DS')) define('DS',DIRECTORY_SEPARATOR);
/**
 * function that outputs to the browser a table
 * to be served mainly as a side menu
 * Reads from a file in -json style- the page title to display
 * and the link to direct the user
 *
 * @param string $navPath : The path to the file to read from
 * @param string $header  : The table header, default null
 * @param string $class   : The class of the table
 * @return void	: Outputs directly to the page
 */
function sideMenu ($navPath = '', $class = '', $header = '')
{
    if (empty($navPath))
        return;
    $activePage = basename($_SERVER['PHP_SELF']);

    $navRows = file($navPath);
    echo '<table class="' . $class . '">';
    echo '<tbody>';
    echo '<th>' . $header . '</th>';

    foreach ($navRows as $row) {
        $nav  = explode('*', $row);
        $page = trim($nav[0]);
        $link = trim($nav[1]);
        
        echo '<tr>';
        echo '<td><a href="' . $link . '">' . $page . '</a></td>';
        echo '</tr>';
    }
    echo '</tbody>';
    echo '</table>';
}

?>